package me.hl.proxy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by pulangke on 2017/2/10.
 */
public class MyInvocation implements InvocationHandler {
    private static Logger logger = LoggerFactory.getLogger(MyInvocation.class);

    private Object object;

    private MyFilter myFilter;

    public MyInvocation(Object object) {
        this.object = object;
    }

    public MyInvocation(Object target, MyFilter filter) {
        this.object = target;
        this.myFilter = filter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (args != null) {
            for (Object o : args) {
                if (o instanceof Integer) {
                    myFilter.filter((Integer) o);
                }
            }
        }
        return method.invoke(object, args);
    }
}
